package com.lbxz.ocrapi.controller;

import com.lbxz.ocrapi.domain.dto.TextAccuracyLocationDto;
import com.lbxz.ocrapi.domain.param.OcrParam;
import com.lbxz.ocrapi.response.ResponseResult;
import com.lbxz.ocrapi.service.OcrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * OCR文本识别接口
 */
@RestController
@RequestMapping("/text")
@Validated
public class OcrTextController {
    @Autowired
    private OcrService ocrService;

    @PostMapping("/text-only")
    public ResponseResult<List<String>> textOnly(@RequestBody @Valid OcrParam ocrParam){
        List<String> textOcrDtos = ocrService.ocrText(ocrParam.getImgBase64(), ocrParam.getImgType());
        System.out.println(ResponseResult.success(textOcrDtos).toString());
        return ResponseResult.success(textOcrDtos);
    }

    @PostMapping("/text-location-accuracy")
    public ResponseResult<List<TextAccuracyLocationDto>> textLocationAccuracy(@RequestBody @Valid OcrParam ocrParam) {
        List<TextAccuracyLocationDto> ocrList = ocrService.ocrTextAccuracyLocation(
                ocrParam.getImgBase64(),
                ocrParam.getImgType()
        );
        return ResponseResult.success(ocrList);
    }

    @GetMapping("/text-only2")
    public ResponseResult<List<String>> textOnly2(@RequestParam @NotBlank(message = "图片base64不能为空") String imgBase64,
                                                      @RequestParam @NotBlank(message = "图片类型不能为空") String imgTYpe){
        List<String> textOcrDtos = ocrService.ocrText(imgBase64, imgTYpe);
        System.out.println(ResponseResult.success(textOcrDtos).toString());
        return ResponseResult.success(textOcrDtos);
    }
}
